package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.entity.Supplier;
import com.wms.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "快捷到货——供应商管理")
@RestController
@RequestMapping("/suppplier")
public class SupplierController {

    @Autowired
    SupplierService supplierService;

    @ApiOperation(value = "获取供应商信息")
    @GetMapping("/info")
    public ResultBean getAll(){
        List list=supplierService.getAll();
        return R.success("获取成功",list);
    }
    @ApiOperation(value = "多条件获取供应商信息")
    @PostMapping("/condition")
    public ResultBean queryByCondition(@RequestBody Supplier supplier){
        List list=supplierService.queryByCondition(supplier);
        return R.success("获取成功",list);
    }
    @ApiOperation(value = "通过id获取供应商信息")
    @GetMapping("/getById")
    public ResultBean queryById(@RequestParam int id){
        List list=supplierService.queryById(id);
        return R.success("获取成功",list);
    }
    @PostMapping("/saveSupplier")
    @ApiOperation(value = "保存供应商")
    public ResultBean saveSupplier(@RequestBody Supplier supplier){
        int res=supplierService.saveSupplier(supplier);
        return res==1? R.success("保存成功"):R.fail("保存失败");
    }

    @GetMapping
    @ApiOperation(value = "供应商分页信息")
    public ResultBean<PageBean<Supplier>> queryByPage(@RequestParam int page, @RequestParam int pageSize){
        PageBean pageBean=supplierService.queryByPage(page,pageSize);
        return R.success("分页列表",pageBean);
    }
}
